﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Core.IServices.User;
using Api.Core.Model;
using Api.Core.Model.Entity;
using Api.Core.Model.Table;
using Api.Core.Model.User;
using Api.Core.Model.ViewModel;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Api.Core.Controllers
{
    public class UserController : BaseController
    {
        private readonly IUserService _userService;
       
        private readonly IMapper _mapper;

        public UserController(IUserService userService,
             IMapper mapper)
        {
            _userService = userService;
            
            _mapper = mapper;
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("AddUser")]
        public async Task<int> AddUser(UserViewModel model)
        {
            var result = await _userService.Add(_mapper.Map<UserViewModel,UserTable>(model));
            return result;
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AddUserWithGroup")]
        public async Task<BaseResponse<bool>> AddUserWithGroup(UserEntity model)
        {
            var userModel = await _userService.AddUserWithGroup(model);
            return userModel;
        }



        /// <summary>
        /// 根据UserId获取用户组信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet("GetUserGroup")]
        public async Task<BaseResponse<List<UserEntity>>> GetUserGroup(UserViewModel model)
        {
            var result = await _userService.GetUserGroup(model);
            return Result(result);
        }


        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[HttpGet]
        //[Route("user")]
        //[AllowAnonymous]
        //public async Task<PageModel<UserInfoEntity>> GetUser(UserViewModel model)
        //{
        //    var userModel = await _userService.GetUser(model);
        //    return userModel;
        //}
    }
}
